package com.github.raffle.concurrent;

/**
 * @author Stephen Liu
 * @version 1.0.0
 * @since 2017/5/16
 */
public class DeadLock {
    public static void main(String[] args) {
        final Object obj1 = new Object();
        final Object obj2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (obj1) {
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    //ignore
                }

                synchronized (obj2) {
                    System.out.println("thread t1 done.");
                }
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            synchronized (obj2) {
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    //ignore
                }

                synchronized (obj1) {
                    System.out.println("thread t2 done.");
                }
            }
        }, "t2");

        t1.start();
        t2.start();
    }
}
